#include "RessourceMgr.h"
#include "Level.h"
#include "ForumStruct.h"


RessourceMgr::RessourceMgr()
{
}

int RessourceMgr::getFood() const
{
	return m_food;
}

int RessourceMgr::getWood() const
{
	return m_wood;
}

int RessourceMgr::getRock() const
{
	return m_rock;
}

int RessourceMgr::getPop() const
{
	return m_pop;
}

int RessourceMgr::getPopMax() const
{
	return m_popMax;
}

void RessourceMgr::modifyFood(const int food)
{
	m_food += food;
	if(m_food < 0)
		m_food = 0;
}

void RessourceMgr::modifyRock(const int rock)
{
	m_rock += rock;
	if(m_rock < 0)
		m_rock = 0;
}

void RessourceMgr::modifyWood(const int wood)
{
	m_wood += wood;
	if(m_pop < 0)
		m_pop = 0;
}

bool RessourceMgr::popIsHigh() const
{
	if(m_pop >= m_popMax)
		return true;
	else
		return false;
}

void RessourceMgr::modifyPop(const int pop)
{
	m_pop += pop;
	if(m_food < 0)
		m_food = 0;
}

void RessourceMgr::init()
{
	m_wood = 10;
	m_rock = 20;
	m_food = 30;
	m_pop = 0;
	m_popMax = 0;
}

void RessourceMgr::maj(Level *level)
{
	std::vector<Struct*> *structure = level->getStruct();
	std::vector<Unit*> *unit = level->getUnit();

	unsigned int e;
	m_popMax = 0;
	m_pop = 0;
	for(e = 0; e < structure->size(); e++)
	{
		if(typeid(*(structure->at(e))) == typeid(ForumStruct))
			m_popMax += 10;
	}
	for(e = 0; e < unit->size(); e++)
	{
		if(typeid(*(unit->at(e))) == typeid(Unit))
			m_pop++;
	}
	if(m_pop > m_popMax)
		m_pop = m_popMax;
}